<template>
    <div class="build-toggle">
        <el-button @click="createPoints">生成点位</el-button>
        <el-button @click="destroyPoints">销毁点位</el-button>

    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getMyProjectManager } from "@/getMyProjectManager";
import { ESImageLabel, ESPoi2D, ESUeViewer } from "esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main";
const myProjectManager = getMyProjectManager()
const data = [
    {
        "x": -1895 * 2,
        "y": -850 * 2,
        "z": 193
    },
    {
        "x": -460 * 2,
        "y": -715 * 2,
        "z": 193
    },
    {
        "x": 110 * 2,
        "y": -665 * 2,
        "z": 193
    },
    {
        "x": 1200 * 2,
        "y": -555 * 2,
        "z": 193
    },
    {
        "x": -175 * 2,
        "y": -325 * 2,
        "z": 193
    },
    {
        "x": -140 * 2,
        "y": -1055 * 2,
        "z": 193
    }, {
        "x": 776.19 * 4,
        "y": -2248.80 * 4,
        "z": -110
    }
]
let cameraList: ESImageLabel[] = []

const createPoints = () => {
    data.forEach(point => {
        const viewer = myProjectManager.activeViewer as ESUeViewer
        viewer.UEPositionToLonLatAlt([point.x, point.y, point.z]).then(res => {
            const e = myProjectManager.createSceneObject(ESImageLabel)
            if (!e) return
            e.position = res as [number, number, number]
            e.anchor = [0.5, 1]
            e.sizeByContent = false
            e.size = [35, 45]
            e.allowPicking = true
            e.dispose(e.widgetEvent.don((info) => {
                if (info && info.type === "leftClick") {
                    console.log("视像头拾取信息", info, e)
                }
            }))
            cameraList.push(e)
        })
    })

}
/**
 * 销毁摄像头
 */
const destroyPoints = () => {
    cameraList.forEach((e) => {
        myProjectManager.destroySceneObject(e)
    })
    cameraList.length = 0
}

</script>
<style scoped></style>
